package com.uchengwang.ui.cm_ui.cycle.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.functions.http.config.BaseConfig;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.cm_ui.cycle.bean.SnsBean;
import com.uchengwang.ui.cm_ui.release.ui.ChooseVideoActivity;
import com.uchengwang.ui.cm_ui.release.ui.ReleaseActActivity;
import com.uchengwang.ui.cm_ui.release.ui.ReleaseRoomMeetActivity;
import com.uchengwang.ui.cm_ui.release.ui.ReleaseVoteActivity;
import com.uchengwang.ui.cm_ui.ucity.ui.ReleaseDynamicActivity;
import com.uchengwang.ui.view.SnsPopupWindow;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2018/4/25.
 */

public class SnsAdapter extends RecyclerView.Adapter<SnsAdapter.SnsVH>{
    private Context context;
    private List<SnsBean> list = new ArrayList<>();
    private SnsPopupWindow window;

    public SnsAdapter(Context context, SnsPopupWindow window, List<SnsBean> list){
        this.context = context;
        this.window = window;
        this.list = list;
    }


    @Override
    public SnsVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_sns_view, parent, false);
        return new SnsVH(view);
    }

    @Override
    public void onBindViewHolder(SnsVH holder, final int position) {
        final SnsBean bean = list.get(position);
        ImageManager.getInstance().loadImage(context, holder.image, bean.getResId(), ImageManager.ImageType.NARMOL);

        holder.text.setText(bean.getTitle());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = null;
                switch (bean.getTitle()){
                    case "享说":
                        intent = new Intent(context, ReleaseDynamicActivity.class);
                        break;
                    case "视频":
                        intent = new Intent(context, ChooseVideoActivity.class);
                        intent.putExtra(BaseConfig.TYPE, 5);
                        break;
                    case "投票":
                        intent = new Intent(context, ReleaseVoteActivity.class);
                        break;
                    case "活动":
                        intent = new Intent(context, ReleaseActActivity.class);
                        break;
                    case "会场":
                        intent = new Intent(context, ReleaseRoomMeetActivity.class);
                        break;
                }
                if (intent != null){
                    context.startActivity(intent);
                }
                window.dismiss();
            }
        });

        if (position == list.size()-1){
            //最后一个 将分割线去掉
            holder.sns_diver.setVisibility(View.GONE);
        }else {
            holder.sns_diver.setVisibility(View.VISIBLE);
        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class SnsVH extends RecyclerView.ViewHolder {
        private View itemView;
        private ImageView image;
        private TextView text, sns_diver;

        public SnsVH(View view) {
            super(view);

            itemView = view;
            AutoUtils.auto(view);

            image = view.findViewById(R.id.sns_image);
            text = view.findViewById(R.id.sns_text);
            sns_diver = view.findViewById(R.id.sns_diver);


        }
    }
}
